package controller;

import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;

public class DateRange implements Iterator<Date>, Iterable<Date> {

	private Calendar end = Calendar.getInstance();
	private Calendar current = Calendar.getInstance();
	private int field = Calendar.DAY_OF_WEEK;
	private int index = 0;

	public DateRange(Date start, Date end) {
		this.end.setTime(end);
		this.current.setTime(start);
	}

	public void setIterationField(int field) {
		this.field = field;
	}

	public boolean hasNext() {
		if (index != 0) {
			current.add(field, 1);
		}
		return !current.after(end);
	}

	public Date next() {
		index++;
		return current.getTime();
	}

	public void remove() {
		throw new UnsupportedOperationException("Cannot remove");
	}

	public Iterator<Date> iterator() {
		return this;
	}

}